package com.example.tacocloud.service;

import com.example.tacocloud.bean.User;
import com.example.tacocloud.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        User user = userMapper.findByUsername(userName);
        if (user != null) return user;
        throw new UsernameNotFoundException("User " + userName + "not found");
    }
}
